package cn.tedu.yl.parentd_department.service.impl;

import cn.tedu.yl.parentd_department.mapper.ParentdDepartmentMapper;
import cn.tedu.yl.parentd_department.pojo.dto.ParentdDepartmentQuery;
import cn.tedu.yl.parentd_department.pojo.dto.ParentdDepartmentSaveParam;
import cn.tedu.yl.parentd_department.pojo.entity.ParentdDepartment;
import cn.tedu.yl.parentd_department.pojo.vo.ParentdDepartmentVO;
import cn.tedu.yl.parentd_department.service.ParentdDepartmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
@Slf4j
public class ParentdDepartmentServiceImpl implements ParentdDepartmentService {

    @Autowired
    private ParentdDepartmentMapper parentdDepartmentMapper;
    @Override
    public List<ParentdDepartmentVO> select(ParentdDepartmentQuery parentdDepartmentQuery) {
        return parentdDepartmentMapper.selectParentdDepartment(parentdDepartmentQuery);
    }

    @Override
    public void save(ParentdDepartmentSaveParam parentdDepartmentSaveParam) {
        ParentdDepartment parentdDepartment=new ParentdDepartment();
        BeanUtils.copyProperties(parentdDepartmentSaveParam,parentdDepartment);
        if (parentdDepartment.getId()==null){
            parentdDepartmentMapper.insertParentdDepartment(parentdDepartment);
        }
        else {
            parentdDepartmentMapper.updateParentdDepartment(parentdDepartment);
        }
    }
}
